package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class Sale here.
 * 
 * @author (Gruppe 2) 
 * @version (a version number or a date)
 */
public class Sale
{
    private int id;
    private String regDate;
    private String status;
    private double totalPrice;
    private Customer customer;
    private BusinessCustomer business;
    private ArrayList<Partsale> partsale;
    
    public Sale(int id, String regDate, String status)
    {
        this.id = id;
        this.regDate = regDate;
        this.status = status;
        customer = null;
        business = null;
        partsale = new ArrayList<Partsale>();
    }
    
    public int getId()
    {
        return id;
    }
    
    public String getRegDate()
    {
        return regDate;
    }
    
    public String getStatus()
    {
        return status;
    }
    
    public double getTotalPrice()
    {
        return totalPrice;
    }
    
    public Customer getCustomer()
    {
        return customer;
    }
    
    public BusinessCustomer getBusiness()
    {
        return business;
    }
    
    public ArrayList<Partsale> getPartsale()
    {
        return partsale;
    }
    
    public void setId(int id)
    {
        this.id = id;
    }
    
    public void setRegDate(String regDate)
    {
        this.regDate = regDate;
    }
    
    public void setStatus(String status)
    {
        this.status = status;
    }
    
    public void setCustomer(Customer customer)
    {
        if(business == null)
        {
            this.customer = customer;
        }
        else
        {
            System.out.println("\f A business customer has already been added to this sale");
        }
    }
    
    public void setBusiness(BusinessCustomer business)
    {
        if(customer == null)
        {
            this.business = business;
        }
        else
        {
            System.out.println("\f A regular customer has already been added to this sale");
        }
    }
    
    public void addPartsale(Partsale partsale)
    {
        this.partsale.add(partsale);
    }
    
    public double calcTotalPrice()
    {
        int i = 0;
        Partsale tempPartsale;
        Item tempItem;
        double tempPrice;
        double tempTotalPrice = 0;
        while(i < partsale.size())
        {
            tempPartsale = partsale.get(i);
            tempItem = tempPartsale.getItem();
            tempPrice = tempItem.getPrice();
            tempTotalPrice = tempTotalPrice + tempPrice * tempPartsale.getQuantity();
            i ++;
        }
        return tempTotalPrice;
    }
}
